package xyz.zhangyi.onjava.java8.example.lambda.orchard;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

public class BuildInPredicateOrchard extends Orchard {
    @Override
    public List<Apple> filter() {
        return filter(new Predicate<Apple>() {
            @Override
            public boolean test(Apple apple) {
                return apple.getColor().equals("green");
            }
        });
    }

    private List<Apple> filter(Predicate<Apple> predicate) {
        ArrayList<Apple> result = new ArrayList<>();
        for (Apple apple : apples) {
            if (predicate.test(apple)) {
                result.add(apple);
            }
        }
        return result;
    }
}
